package com.lhhu.demo.controller;

import com.lhhu.demo.bean.UserInfo;
import com.lhhu.demo.config.LogAnnotation;
import com.lhhu.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther 虎
 * @Data 2021/3/16 13:28
 * @Version 1.0
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/addOneUser")
    public int addOneUser(UserInfo userInfo){
        return userService.addOneUser(userInfo);
    }

    @GetMapping("/selectUserByOpenid")
    public List<UserInfo> selectUserByOpenid(String openid){
        return userService.selectUserByOpenid(openid);
    }

    @GetMapping("/getAllUser")
    public List<UserInfo> getAllUser(){
        return userService.getAllUser();
    }

    @GetMapping("/getUserByName")
    public List<UserInfo> getUserByName(String nickName){
        return userService.getUserByName(nickName);
    }

    @GetMapping("/getUserByGender")
    public List<UserInfo> getUserByGender(String gender){
        return userService.getUserByGender(gender);
    }

    @GetMapping("/getUserByTag")
    public List<UserInfo> getUserByTag(String tag){
        return userService.getUserByTag(tag);
    }

    @LogAnnotation(module = "用户管理模块",action = "更新用户信息")
    @PutMapping("/updateUserMessage")
    public int updateUserMessage(String codes,String openid,String tag){
        UserInfo userInfo = new UserInfo();
        userInfo.setOpenid(openid);
        userInfo.setTag(tag);
        return userService.updateUserMessage(codes,userInfo);
    }

    @LogAnnotation(module = "用户管理模块",action = "删除用户")
    @DeleteMapping("/deleteOneUser")
    public int deleteOneUser(String codes,String openid){
        return userService.deleteOneUser(codes,openid);
    }
}
